<!DOCTYPE html>
<html>
{include file="public1/_header" /}

<body>
<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>倒计时</cite></a>
			</span>
    <a class="layui-btn layui-btn-small" style="float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-hide" id="test" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon">&#xe642;</i>清除倒计时
            </button>
        </div>
    </script>
</div>
<script type="text/javascript">
    var url = "__STATIC__/admin/"
    layui.use(['util', 'table','form'], function() {
        var table = layui.table;
        var tableIns = table.render({
            id: 'testReload',
            elem: '#test',
            url: "{:url('bancard/Countdown/lists')}",
            method: "POST",
            request: {
                pageName: 'offset', //页码的参数名称，默认：page
                limitName: 'limit' //每页数据量的参数名，默认：limit
            },
            toolbar: '#toolbarDemo',
            where: {
                user_id: "{$Think.session.admin.id}",
                school_id: "{$Think.session.schoolInfo.id}"
            },
            cols: [
                [ {
                    field: 'title',
                    title: "标题"
                }, {
                    field: 'closing_date',
                    title: "截止日期",
                    sort: true
                }, {
                    field: 'time_slot',
                    title: "活动时间段",
                    sort: true
                }]
            ],
            page: true
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj) {
            switch (obj.event) {
                case 'add':
                    var index = parent.layer.getFrameIndex(window.name);
                    var lfc = top.layerFrameConfig;
                    var info = lfc.iframeB.info;
                    var ids =  lfc.iframeB.ids;
                    var device_ids =  lfc.iframeB.device_ids;
                    var data = {};
                    data.id = -1;
                    data.device_ids = device_ids;
                    data.ids = ids;
                    $.post("{:url('countdown')}", data, function(res) {
                        if (res.code == 0) {
                            layer.msg('设置成功', {
                                icon: 1,
                                time: 300
                            }, function() {
                                parent.layer.close(index); //再执行关闭
                                info.reload()
                            });

                        } else {
                            layer.msg(res.message)
                            info.reload()
                        }
                    })
                    break;
            };
        });

        //监听单元格编辑
        table.on('row(test)', function(obj) {
            var index = parent.layer.getFrameIndex(window.name);
            var lfc = top.layerFrameConfig;
            var info = lfc.iframeB.info;
            var ids =  lfc.iframeB.ids;
            var device_ids =  lfc.iframeB.device_ids;
            var data = obj.data;
            data.device_ids = device_ids;
            data.ids = ids;
            $.post("{:url('countdown')}", data, function(res) {
                if (res.code == 0) {
                    layer.msg('设置成功', {
                        icon: 1,
                        time: 300
                    }, function() {
                        parent.layer.close(index); //再执行关闭
                        info.reload()
                    });

                } else {
                    layer.msg(res.message)
                    info.reload()
                }
            })

        });
    });

</script>
</body>
</html>
